<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>{$is_language?'融資記錄':'Records of financing'}</title>
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <link rel="stylesheet" href="__MODULE_LIBS__/css/weui.min.css">
    <link rel="stylesheet" href="__MODULE_LIBS__/css/jquery-weui.css">
    <link rel="stylesheet" href="__MODULE_LIBS__/css/demos.css">
    <script src="__MODULE_LIBS__/js/jquery-2.1.4.js"></script>
    <script src="__MODULE_LIBS__/js/fastclick.js"></script>
    <script src="__MODULE_LIBS__/js/jquery-weui.js"></script>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }

        html {
            width: 100%;
            height: 100%;
            font-size: 20px;
            font-family: "Microsoft YaHei", "宋体", "Segoe UI", "Lucida Grande", Helvetica, Arial, sans-serif, FreeSans, Arimo;
            background: #F3F3F3;
        }

        body {
            margin: 0 auto;
            max-width: 750px;
            height: 100%;
            background: #F7F7F7;
        }

        /*顶部导航栏处的样式*/
        .navbar {
            position: relative;
            width: 100%;
            height: 2rem;
            font-size: 16px;
            color: #fff;
            line-height: 2rem;
            background: #373553;
        }

        .navbar-item {
            position: absolute;
            left: 0;
            top: 0;
            display: block;
            width: 3.2rem;
            height: 2rem;
            font-size: 14px;
            color: #fff;
            text-align: center;
        }

        .navbar-item > img {
            width: 0.8rem;
            height: 0.7rem;
            vertical-align: middle;
        }

        .navbar-center {
            text-align: center;
        }

        /*主体部分的样式*/
        .content {
            width: 100%;
            margin-bottom: 60px;
        }

        .weui-cells {
            margin-top: 0.7rem;
            font-size: 0.7rem;
        }

        .weui-cell {
            padding: 0.4rem 0.5rem;
        }

        .weui-cell__hd {
            width: 5.0rem;
        }

        .weui-cell__bd {
            text-align: center;
        }

        .num {
            font-size: 0.6rem;
            color: #777;
        }

        .money {
            font-size: 0.65rem;
            color: #F44444;
        }

        .weui-cell__ft {
            padding-left: 0.2rem;
            width: 5rem;
        }

        .time {
            font-size: 0.5rem;
            color: #888888;
        }

        .sellbtn, .sellbtn_1, .sellbtn_2 {
            padding: 0.3rem 0.3rem;
            margin: .1rem 0;
            background: #fff;
            color: #f44444;
            border: 0;
            outline: 0;
            font-size: 0.6rem;
            border-radius: 0.2rem;
            width: 100px;
        }

        .selllist {
            position: fixed;
            bottom: 0;
            width: 100%;
            max-width: 750px;
            height: 2.2rem;
            font-size: 0.75rem;
            text-align: center;
            line-height: 2.2rem;
            background: #468EE6;
            display: flex;
        }

        .selllist > a {
            display: block;
            width: 100%;
            height: 100%;
            color: #fff;
        }

        .sell-dlog {
            position: fixed;
            top: 0px;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            z-index: 100;
            display: none;
        }

        .dlog {
            position: relative;
            top: 8rem;
            left: 0;
            margin: 0 auto;
            padding: 0.5rem;
            width: 13rem;
            height: auto;
            background: #fff;
            border-radius: 0.4rem;
            z-index: 200;
        }

        .sell-close {
            position: absolute;
            top: 0rem;
            right: 0rem;
            width: 2rem;
            height: 1.4rem;
            text-align: center;
            line-height: 1.4rem;
            cursor: pointer;
        }

        .sellForm {
            margin-top: 0.5rem;
            width: 100%;
            font-size: 0.65rem;
        }

        .sellForm > p {
            display: block;
            width: 100%;
            margin-top: 0.6rem;
            margin-bottom: 0.4rem;
            text-align: center;
        }

        .sellForm input[type="number"] {
            padding-left: 0.3rem;
            width: 7.4rem;
            border: 0;
            border-bottom: 1px #F44444 solid;
            outline: 0;
        }

        .btn {
            width: 10rem;
            height: 1.5rem;
            color: #FFFFFF;
            background: #F44444;
            border: 0;
            border-radius: 0.2rem;
            outline: 0;
            cursor: pointer;
        }

        .pagination > li {
            float: left;
            padding: 2px 6px;
            margin: 0 4px;
            list-style: none;
            color: #fff;
            background: #aaa;
            border-radius: 5px;
        }

        .pagination > li > a {
            color: #fff;
        }

        .pagination > li.active {
            background: #f44444;
        }

        .weui-cell::before {
            border: none !important;
        }

        .issue-dlog, .modify-dlog, .buy-dlog {
            position: fixed;
            top: 0px;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.4);
            z-index: 10000;
            display: none;
        }

        .dlog {
            position: relative;
            top: 5rem;
            left: 0;
            margin: 0 auto;
            padding: 0.5rem;
            width: 14.5rem;
            height: auto;
            background: #fff;
            border-radius: 0.4rem;
            z-index: 100000;
        }

        .issue-close, .modify-close, .buy-close {
            position: absolute;
            top: 0rem;
            right: 0rem;
            width: 2rem;
            height: 1.4rem;
            text-align: center;
            line-height: 1.4rem;
            cursor: pointer;
        }

        .issueForm, .modifyForm, .buyForm {
            margin-top: 0.5rem;
            width: 100%;
            font-size: 0.65rem;
        }

        .issueForm > p, .modifyForm > p, .buyForm > p {
            display: block;
            width: 100%;
            height: 1.6rem;
            line-height: 1.6rem;
            margin-top: 0.4rem;
            margin-bottom: 0.3rem;
            text-align: center;
        }

        .issueForm > .visi, .modifyForm > .visi {
            margin-left: 0.25rem;
            text-align: left;
        }

        .issueForm input[type="text"],
        .modifyForm input[type="text"],
        .buyForm input[type="number"],
        .issueForm input[type="datetime"],
        .issueForm input[type="datetime-local"],
        .modifyForm input[type="datetime-local"] {
            padding-left: 0.3rem;
            width: 100%;
            height: 1.4rem;
            border: 0;
            border-bottom: 1px #F44444 solid;
            outline: 0;
        }

        .issuebtn, .modifybtn, .buybtn {
            width: 10rem;
            height: 1.5rem;
            color: #FFFFFF;
            background: #F44444;
            border: 0;
            border-radius: 0.2rem;
            outline: 0;
            cursor: pointer;
        }

        .agree, .refuse, .pingcang {
            padding: 0.1rem 0.2rem;
            color: #ffffff;
            background: #F44444;
            border: 0;
            outline: 0;
            border-radius: 3px;
            margin: 2px;
        }
        .weui-cell__bd {
            text-align: left;
            margin-left: 5px;
        }
    </style>
</head>
<body>
<header class="navbar">
    <a href="{:url('index/index')}" class="navbar-item">
        <img src="__MODULE_LIBS__/img/back.png"/>&nbsp;{$is_language?'返回':'Return'}
    </a>
    <div class="navbar-center">{$is_language?'融資記錄':'Records of financing'}</div>
    <div class="navbar-item1">
        <select name="" id="yy">
            <option value="1" {$is_language?
            'selected':''}>中文</option>
            <option value="0" {$is_language?
            '':'selected'}>English</option>
        </select>
    </div>
</header>
<div class="content">

    {foreach $data as $vo}
    <div class="weui-cells">
        <!--重复部分开始-->
        <div class="weui-cell" style="border-bottom: 1px solid #eee;">
            <p class="time">{$is_language?'購買時間':'Purchase time'}：{$vo['create_time']|date="Y-m-d H:i:s",###}</p>
            {if $vo['type']==5}
            {if $vo['status']==1}
            {if $vo['is_selling']!==1}
            <p class="time">{$is_language?'賣出時間':'Selling time'}:${$vo['end_time']|date="Y-m-d H:i:s",###}</p>
            {/if}
            {/if}
            {/if}
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd">
                <p class="proname">{$vo['goods_name']}</p>
                {if $vo['status']==4}
                <p class="num">
                    {$is_language?'數量':'Number'}：{$vo['surplus_sum']?$vo['surplus_sum']:$vo['sum']}{$is_language?'個':'individual'}</p>
                {else}
                <p class="num">{$is_language?'數量':'Number'}：{$vo['surplus_sum']}{$is_language?'個':'individual'}</p>
                {/if}
            </div>
            <div class="weui-cell__bd">
                <p class="money">{$is_language?'購買價':'Purchase price'}：${$vo['money']}</p>
                <p class="money">{$is_language?'當前價':'Current price'}：${$vo['goods_money']}</p>
            </div>
            <div class="weui-cell__ft">
                {if $vo['type']==4}
                <p class="money">{$is_language?'資產總值':'Gross assets'}：${$vo['sum']*$vo['goods_money']}</p>
                {/if}
                {if $vo['type']==5}
                <p class="money">{$is_language?'資產總值':'Gross assets'}：${$vo['sum']*$vo['money2']}</p>
                {/if}
                <p class="money">{$is_language?'日利率':'Daily rates'}：{$vo['capital_interest']*100}%</p>
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd">
                <p class="money">{$is_language?'配資比例':'With the proportion of capital'}：1:{$vo['capital_pro']}</p>
                <p class="money">{$is_language?'配資天數':'Allocated time'}：{$vo['past_time']}</p>
                <p class="money">{$is_language?'應付利息':'Interest paid'}：${$vo['redeem_money']}</p>
                <p class="money">{$is_language?'實際收益':'Actual benefits'}：${$vo['user_money']}</p>
                {if $vo['type']==5}
                {if $vo['status']==1}
                {if $vo['is_selling']!==1}
                <p class="money">{$is_language?'實付利息':'Selling time'}:${$vo['capital_money']}</p>
                {/if}
                {/if}
                {/if}
            </div>
            <div class="weui-cell__bd">
                <p class="money">{$is_language?'平倉價格':'Practice closing price'}：${$vo['selling_price']}</p>
                <p class="money">{$is_language?'補倉價格':'Practice make-up price'}：${$vo['margin_price']}</p>
                <p class="money">{$is_language?'融資金額':'Funding
                    amount'}：${$vo['money']*$vo['surplus_sum']*$vo['capital_pro']/($vo['capital_pro']+1)}</p>
                {if $vo['type']==5}
                {if $vo['status']==1}
                {if $vo['is_selling']!==1}
                <p class="money">{$is_language?'實際賣出價格':'Actual selling price'}:${$vo['money2']}</p>
                {/if}
                {/if}
                {/if}
                {if $vo['actual_sum']}
                <p class="money">{$is_language?'本金':'principal'}：${$vo['money']*$vo['actual_sum']/(1+$vo['capital_pro'])}</p>
                {else}
                <p class="money">{$is_language?'本金':'principal'}：${$vo['money']*$vo['sum']/(1+$vo['capital_pro'])}</p>
                {/if}
            </div>
            <div class="weui-cell__ft">
                <input type="hidden" value="{$vo['id']}">
                <p class="money">{$is_language?'保證金':'Bond'}：${$vo['money3']}</p>
                {if $vo['type']==4}
                {if $vo['status']==0}
                <p class="money">{$is_language?'正在匹配':'Matching'}</p>
                {elseif $vo['status']==1}


                <p class="money">
                    {if $vo['margin_money']>$vo['goods_money']*$vo['surplus_sum']+$vo['money3']}
                    <button class="agree">{$is_language?'繳納保證金':'Pay deposit'}</button>
                    {/if}
                    <button class="refuse">{$is_language?'出售':'Sell'}</button>
                </p>


                <!--<p class="money"><button class="pingcang">{$is_language?'平倉':'Open'}</button></p>-->
                {elseif $vo['status']==2}
                <p class="money">{$is_language?'匹配失敗':'Match failure'}</p>
                {elseif $vo['status']==4}
                <p class="money">{$is_language?'等待配資':'Waiting for money'}</p>
                {elseif $vo['status']==5}
                <p class="money">{$is_language?'配資取消':'Cancellation of funds'}</p>
                {/if}
                {/if}

                {if $vo['type']==5}
                {if $vo['status']==0}
                {if $vo['is_force']==1}
                <p class="money">{$is_language?'強制平倉中':'Forced to open positions'}</p>
                {else}
                <p class="money">{$is_language?'出售中':'In the sale'}</p>
                {/if}
                {elseif $vo['status']==1}

                {if $vo['is_force']==1}
                <p class="money">{$is_language?'強制平倉':'Forced liquidation'}</p>
                {else}
                <p class="money">{$is_language?'用戶賣出':'Sell by users'}</p>
                {/if}
                {elseif $vo['status']==2}
                {if $vo['is_force']==1}
                <p class="money">{$is_language?'平倉被拒':'The flat is rejected'}</p>
                {else}
                <p class="money">{$is_language?'出售失敗':'Sale failure'}</p>
                {/if}
                {/if}
                {/if}
            </div>
        </div>
    </div>
    {/foreach}

    <!--重复部分结束-->
</div>
<!--<div class="selllist">-->
<!--<a href="{:url('index')}">{$is_language?'配資商設置':'Funder settings'}</a>-->
<!--</div>-->
<input type="hidden" name="yuyan" value="<?php echo @$is_language?>" id="yuyan">
<!--售出的弹出框开始-->
<div class="sell-dlog">
    <div class="dlog">
        <div class="sell-close">X</div>
        <form action="" class="sellForm">
            <p>
                {$is_language?'請選擇平倉方式':'Please choose a flat way'}：
            </p>
            <p>
                <label><input name="is_automatic" type="radio" value="1"
                              checked/>{$is_language?'自動':'Automatic'}</label>
                <label><input name="is_automatic" type="radio" value="0"/>{$is_language?'手動':'Manual'}</label>
            </p>
            <p>
                <input type="button" class="btn" id="pc" value="{$is_language?'確認':'Determine'}"/>
            </p>
        </form>
    </div>
</div>

<script type="text/javascript">
    $('.agree').click(function () {
        var id = $(this).parents('.weui-cell__ft').find('input').val();
        var url = "{:url('capital/bond_ajax')}";
        var url1 = "{:url('capital/bond')}";
        $.post(url, {id: id}, function (data) {
            console.log(data);
            if (data.code == 0) {
                $.alert(data.msg)
            } else {
                $.confirm({
                    title: '提示(confirm)',
                    text: '確定繳納保證金(Do you decide to pay the deposit)：$' + data.content + '？',
                    onOK: function () {
                        $.post(url1, {id: id}, function (data) {
                            $.alert({
                                title: '提示（confirm）',
                                text: data.msg,
                                onOK: function () {
                                    window.location.reload();
                                }
                            })
                        })
                    }
                })
            }
        })
    })

    $('.refuse').click(function () {
        var id = $(this).parents('.weui-cell__ft').find('input').val();
        var url = "{:url('capital/sell')}";
        $.confirm({
            title: '提示(confirm)',
            text: '確定出售嗎？（Do you make sure to sell it？）',
            onOK: function () {
                $.post(url, {id: id}, function (data) {
                    $.alert({
                        title: '提示（confirm）',
                        text: data.msg,
                        onOK: function () {
                            window.location.reload();
                        }
                    })
                })
            }
        })
    })

    //    $('.pingcang').click(function () {
    //        var id = $(this).parents('.weui-cell__ft').find('input').val();
    //        var type= 'sell';
    //        var url = "{:url('capital/capital_order_ajax')}";
    //        $.confirm({
    //            title: '提示(confirm)',
    //            text: '確定平倉嗎？（Do you want to set up a flat？）',
    //            onOK: function () {
    //                $.post(url, {id:id,type:type}, function (data) {
    //                    $.alert({
    //                        title: '提示（confirm）',
    //                        text: data.msg,
    //                        onOK: function () {
    //                            window.location.reload();
    //                        }
    //                    })
    //                })
    //            }
    //        })
    //    })

    $('.issue-close').click(function () {
        $(".issue-dlog").css('display', 'none');
        $('body').css({
            "overflow-x": "auto",
            "overflow-y": "auto"
        });
        //然后点击取消或者确定时再取消body上的绑定
        $("body").off("touchmove");
    });
    $(document).on("change", 'select#yy', function () {
        var yy = $(this).val();
        console.log(yy)
        var url = "{:url('index/language')}";
        $.post(url, {language: yy}, function (res) {
            window.location.reload();
        })
    });
    $(function () {
        FastClick.attach(document.body);

        //是否售出处的弹出框
        $(".sellbtn").click(function () {
            var hidid = $(this).parents(".btn_bot").find('input').val();
            $(".sellid").val(hidid);
            $.ajax({
                type: "POST",
                url: "{:url('ajax')}",
                dataType: "json",
                data: {
                    id: hidid
                },
                success: function (data) {
                    var shouxu = data.content.con.sell_fee;
                    var danjia = data.content.order.goods_money;
                    var zong = eval(danjia * shouxu) + eval(danjia);
                    var c_s = eval(danjia * shouxu).toFixed(2);
                    $('#shouxu').html(c_s);
                    $('.numInput').bind('input propertychange', function () {
                        var shouxu = data.content.con.sell_fee;
                        var danjia = data.content.order.goods_money;
                        var num = $('.numInput').val();
                        var z_shouxu = eval(shouxu * danjia * num).toFixed(2);
                        var zong = eval(z_shouxu) + eval(danjia * num);
                        var z_zong = eval(zong).toFixed(2);
                        $('#shouxu').html(z_shouxu);
                    });
                    $("#shouchu").click(function (e) {
                        if ($('.numInput').val() < 1) {
                            e.preventDefault();
                            var yuyan = $('#yuyan').val();
                            if (yuyan == 1) {
                                $.alert("輸入的數量不能小於1!");
                            } else {
                                $.alert("The number of inputs should not be less than 1!");
                            }
                            return false;
                        } else {
                            var yuyan = $('#yuyan').val();
                            if (yuyan == 1) {
                                $.confirm({
                                    title: '提示',
                                    text: '確定賣出嗎？',
                                    onOK: function () {
                                        //点击确认
                                        $.showLoading("賣出處理中");
                                        $.ajax({
                                            type: "POST",
                                            url: "{:url('sell')}",
                                            dataType: "json",
                                            data: {
                                                id: $(".sellid").val(),
                                                sum: $('.numInput').val()
                                            },
                                            success: function (data) {
                                                $.hideLoading();
                                                $.alert(data.msg + "<br/>" + data.msg1, function () {
                                                    location.href = "";
                                                });
                                            }
                                        })
                                    }
                                })
                            } else {
                                $.confirm({
                                    title: 'Prompt',
                                    text: 'Are you sure you sell?',
                                    onOK: function () {
                                        //点击确认
                                        $.showLoading("Sell processing");
                                        $.ajax({
                                            type: "POST",
                                            url: "{:url('sell')}",
                                            dataType: "json",
                                            data: {
                                                id: $(".sellid").val(),
                                                sum: $('.numInput').val()
                                            },
                                            success: function (data) {
                                                $.hideLoading();
                                                $.alert(data.msg + "<br/>" + data.msg1, function () {
                                                    location.href = "";
                                                });
                                            }
                                        })
                                    }
                                })
                            }
                        }
                    })
                }
            });

            $(".sell-dlog").css('display', 'block');
            $('body').css({
                "overflow-x": "hidden",
                "overflow-y": "hidden"
            });
            //阻止默认
            $("body").on("touchmove", function (event) {
                event.preventDefault;
            }, false);

        });


        $('.sell-close').click(function () {
            $(".sell-dlog").css('display', 'none');
            $('body').css({
                "overflow-x": "auto",
                "overflow-y": "auto"
            });
            //然后点击取消或者确定时再取消body上的绑定
            $("body").off("touchmove");
            $('.numInput').val(1);
        });

        $('.sellbtn_1').click(function () {
            var hidid = $(this).parents(".btn_bot").find('input').val();
            var url = "{:url('order/turnout')}?id=" + hidid;
            window.location.href = url;
        })
    })
</script>
</body>
</html>
